package com.mogujie.tt.ui.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.mogujie.tt.DB.sp.RegisterSp;
import com.mogujie.tt.R;
import com.mogujie.tt.ui.base.QZBaseActivity;
import com.mogujie.tt.ui.base.TTBaseActivity;
import com.mogujie.tt.utils.SubmitUserDetailsTask;

/**
 * Created by user on 2015/10/29.
 */
public class UpdateEmailActivity extends QZBaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater.from(this).inflate(R.layout.tt_activity_update_email,topContentView);
        showTopInformation("修改邮箱");

        final String email = RegisterSp.instance().getSpDetailedInfo().getDetailedEmail();

        final EditText et_email = (EditText) this.findViewById(R.id.et_email);
         et_email.setText(email.toString().trim());

        TextView tv_save = (TextView) this.findViewById(R.id.tv_save);
        tv_save.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String newEmail = et_email.getText().toString().trim();
                if (email.equals(newEmail) || newEmail.equals("")) {
                    return;
                }
                RegisterSp.instance().setdetailedEmailStrConfig(newEmail);
                new SubmitUserDetailsTask(UpdateEmailActivity.this).execute();//提交用户详细信息
                Toast.makeText(UpdateEmailActivity.this, "更新邮箱成功", Toast.LENGTH_SHORT).show();
            }

        });

    }

    /**
     * 显示顶部信息
     */
    private void showTopInformation(String test){
        if(test == null){
            return;
        }
        setTopBarDisplay();
        setCenterText(test);
    }


    public void onClickExit(View view){
        finish();
    }
}
